package tq.com.tqstudent.views;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lib.common.utils.LogUtil;

import tq.com.tqstudent.R;
import tq.com.tqstudent.bean.UserInfo;
import tq.com.tqstudent.ui.activity.classes.ClassActivateActivity;
import tq.com.tqstudent.ui.activity.classes.CommentActivity;
import tq.com.tqstudent.ui.activity.classes.MsgActivity;
import tq.com.tqstudent.ui.activity.classes.NoticeActivity;
import tq.com.tqstudent.ui.activity.classes.SwitchActivity;

/**
 * @Author rames
 * @date 2019/2/27 19:37
 */
public class ClassHeadView extends LinearLayout implements View.OnClickListener{
    private TextView msgCountPoint;

    public ClassHeadView(Context context) {
        super(context);
        init();
    }

    public ClassHeadView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ClassHeadView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        LayoutInflater.from(getContext()).inflate(R.layout.view_class_fragment_head, this);
        findViewById(R.id.notice_layout).setOnClickListener(this);
        findViewById(R.id.msg_layout).setOnClickListener(this);
        findViewById(R.id.card_layout).setOnClickListener(this);
        findViewById(R.id.comment_layout).setOnClickListener(this);
        findViewById(R.id.switch_layout).setOnClickListener(this);
        msgCountPoint = findViewById(R.id.msg_count_tv);
    }

    public void setMsgCountPoint(int count){
        LogUtil.e("setMsgCountPoint count: "+count);
        if(count > 0){
            msgCountPoint.setVisibility(View.VISIBLE);
            msgCountPoint.setText(""+count);
        } else {
            msgCountPoint.setVisibility(View.GONE);
            msgCountPoint.setText(""+0);
        }
    }

    @Override
    public void onClick(View view) {
        if(R.id.notice_layout == view.getId()){
            NoticeActivity.show((Activity) getContext());
        }

        if(!UserInfo.isLogin()){
            LoginTipsDialog dialog = new LoginTipsDialog(getContext());
            dialog.show();
            return;
        }

        switch (view.getId()){
            case R.id.msg_layout:
                MsgActivity.show((Activity) getContext());
                break;
            case R.id.card_layout:
                ClassActivateActivity.show((Activity) getContext());
                break;
            case R.id.comment_layout:
                CommentActivity.show((Activity) getContext());
                break;
            case R.id.switch_layout:
                SwitchActivity.show((Activity) getContext());
                break;
        }
    }
}
